#ifndef UI_H
#define UI_H

#ifdef __cplusplus
extern "C" {
#endif
#include <Arduino.h>
#include <lvgl.h>
#include "my_indev.h"



static void btn_event_cb(lv_event_t * e)
{

    //lv_event_code_t code = lv_event_get_code(e);//获取事件代码,LV_EVENT_PRESSED,LV_EVENT_CLICKED,LV_EVENT_LONG_PRESSED(lvgl库自带，外部驱动只返回有LV_EVENT_PRESSED即可)
    Serial.println("按下");
    static uint32_t cnt = 1;
    lv_obj_t * btn = lv_event_get_target_obj(e);//获取事件对象
    lv_obj_t * label = lv_obj_get_child(btn, 0);//获取子对象
    lv_label_set_text_fmt(label, "%"LV_PRIu32, cnt);
    cnt++;

}

/**
 * Create a button with a label and react on click event.
 */
void lv_example_get_started_2(void)
{
   
 //创建旋转编码器为输入设备
  /*Register at least one display before you register any input devices*/
  static lv_indev_t * indev = lv_indev_create();
  lv_indev_set_type(indev, LV_INDEV_TYPE_ENCODER);   /*See below.*/
  lv_indev_set_read_cb(indev, encoder_read);  /*See below.*/  //绑定输入设备的回调函数

   //  UI设计
  /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    lv_obj_t * btn = lv_button_create(lv_screen_active());     /*Add a button the current screen*/
    lv_obj_set_pos(btn, 60, 95);                            /*Set its position*///按钮左上点坐标
    lv_obj_set_size(btn, 120, 50);                          /*Set its size*/
    lv_obj_add_event_cb(btn, btn_event_cb, LV_EVENT_LONG_PRESSED, NULL);           /*Assign a callback to the button*/

    lv_obj_t * label = lv_label_create(btn);          /*Add a label to the button*/
    lv_label_set_text(label, "Button");                     /*Set the labels text*/
    lv_obj_center(label);
  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  /* 创建group 后面将控件绑定到组即绑定到输入设备 */
  lv_group_t * group = lv_group_create();
  lv_indev_set_group(indev, group);
  lv_group_add_obj(group,btn);
}












#ifdef __cplusplus
} /*extern "C"*/
#endif

#endif /*UI_H*/